<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>여기는 News</title>

<script type="text/javascript" src="scripts/jquery-1.4.min.js"></script>

<script type="text/javascript">
	function setCookie(cookieName, cookieDay) {
		var cookieValue = $('#mytext').val();
		var expire = new Date();
		expire.setDate(expire.getDate() + cookieDay);
		cookies = cookieName + '=' + escape(cookieValue) + '; path=/ ';
		if(typeof cookieDay != 'undefined') {
			cookies += ';expires=' + expire.toGMTString() + ';';
		}
		document.cookie = cookies;
     }
	
	function getCookie(cookieName) {
		cookieName = cookieName + '=';
		var cookieData = document.cookie;
		var start = cookieData.indexOf(cookieName);
		var cookieValue = '';
		if(start != -1) {
			start += cookieName.length;
			var end = cookieData.indexOf(';', start);
			if(end == -1) {
				end = cookieData.length;
			}
			cookieValue = cookieData.substring(start, end);
		}
		return unescape(cookieValue);
	}
     
</script>

</head>
<body>
<section>
<h1>News</h1>
<br/><br/>
<h2>쿠키를 이용한 간단한 로컬 데이터 저장</h2>
<br/><br/>
저장할 값을 입력하세요~~~~~ <input type="text" id=mytext name="mytext">
<br/><br/>
<input type="button" value="입력값 저장" onclick="setCookie('test', 1)">
<input type="button" value="이전에 입력했던 값 보기" onclick="alert(getCookie('test'))">
<input type="button" value="입력값 삭제" onclick="setCookie('test', 'ddd', -1)">
</section>
</body>
</html>